package com.asl.website.sysJoinMain.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.sysJoinMain.domain.JoinUsDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.sysJoinMain.domain.SysJoinMain;
import com.asl.website.sysJoinMain.service.ISysJoinMainService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 加入我们页面配置Controller
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/sysJoinMain/sysJoinMain")
public class SysJoinMainController extends BaseController
{
    @Autowired
    private ISysJoinMainService sysJoinMainService;

    @GetMapping("/content")
    public AjaxResult getJoinUsContent(@RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {
        List<SysJoinMain> contents = sysJoinMainService.selectSysJoinMainList(new SysJoinMain());
        if (contents.isEmpty()) {
            return AjaxResult.error("未配置页面内容");
        }

        return AjaxResult.success(new JoinUsDTO(contents.get(0), acceptLanguage));
    }

    /**
     * 查询加入我们页面配置列表
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysJoinMain sysJoinMain)
    {
        startPage();
        List<SysJoinMain> list = sysJoinMainService.selectSysJoinMainList(sysJoinMain);
        return getDataTable(list);
    }

    /**
     * 导出加入我们页面配置列表
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:export')")
    @Log(title = "加入我们页面配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysJoinMain sysJoinMain)
    {
        List<SysJoinMain> list = sysJoinMainService.selectSysJoinMainList(sysJoinMain);
        ExcelUtil<SysJoinMain> util = new ExcelUtil<SysJoinMain>(SysJoinMain.class);
        util.exportExcel(response, list, "加入我们页面配置数据");
    }

    /**
     * 获取加入我们页面配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:query')")
    @GetMapping(value = "/{joinId}")
    public AjaxResult getInfo(@PathVariable("joinId") Long joinId)
    {
        return success(sysJoinMainService.selectSysJoinMainByJoinId(joinId));
    }

    /**
     * 新增加入我们页面配置
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:add')")
    @Log(title = "加入我们页面配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysJoinMain sysJoinMain)
    {
        return toAjax(sysJoinMainService.insertSysJoinMain(sysJoinMain));
    }

    /**
     * 修改加入我们页面配置
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:edit')")
    @Log(title = "加入我们页面配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysJoinMain sysJoinMain)
    {
        return toAjax(sysJoinMainService.updateSysJoinMain(sysJoinMain));
    }

    /**
     * 删除加入我们页面配置
     */
    @PreAuthorize("@ss.hasPermi('sysJoinMain:sysJoinMain:remove')")
    @Log(title = "加入我们页面配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{joinIds}")
    public AjaxResult remove(@PathVariable Long[] joinIds)
    {
        return toAjax(sysJoinMainService.deleteSysJoinMainByJoinIds(joinIds));
    }
}
